from aiogram.enums import ContentType
from aiogram_dialog import Dialog, Window
from aiogram_dialog.widgets.input import MessageInput
from aiogram_dialog.widgets.kbd import Cancel, ScrollingGroup, Select
from aiogram_dialog.widgets.media import StaticMedia
from aiogram_dialog.widgets.text import Const, Format

from src.bot.dialogs.widgets import LocaleText
from src.bot.states.admin import ImportProductsSG

from ...getters.categories import categories_getter
from .handlers import process_products_file, set_category_id

select_category_window = Window(
    LocaleText("select-category-msg"),
    ScrollingGroup(
        Select(
            Format("{item.name}"),
            "categories_sel",
            lambda category: category.id,
            "categories",
            on_click=set_category_id,
        ),
        width=3,
        height=4,
        id="countriessel",
        hide_on_single_page=True,
    ),
    Cancel(LocaleText("back-btn")),
    state=ImportProductsSG.select_category,
    getter=categories_getter,
)

send_products_xlsx_window = Window(
    Const(
        "Отправьте excel файл с товарами как в образце.\n\n"
        "В образце заполнены только необходимые поля"
    ),
    StaticMedia(path="resources/import_example.xlsx", type=ContentType.DOCUMENT),
    MessageInput(process_products_file, ContentType.DOCUMENT),
    Cancel(LocaleText("back-btn")),
    state=ImportProductsSG.send_products_xlsx,
)

import_products_dialog = Dialog(select_category_window, send_products_xlsx_window)
